package com.liyujie.dyeingmachine.ui;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.liyujie.dyeingmachine.R;


public abstract class BaseActivity<V extends ViewDataBinding> extends AppCompatActivity {
    protected Context mContext;
    protected V binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        /**
         * 全屏
         */
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        /**
         * 保持亮屏
         */
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        //创建
        initCreate();
        //页面接受的参数方法
        initParam();
        //页面数据初始化方法
        //私有的初始化Databinding和ViewModel方法
        initViewDataBinding(savedInstanceState);
        //VM
        initViewModel();
        //
        initView();
        //
        initData();
        //页面事件监听的方法，一般用于ViewModel层转到View层的事件注册
        initViewObservable();

    }

    public void initCreate(){

    }


    public void initParam() {

    }

    /**
     * 初始化根布局
     *
     * @return 布局layout的id
     */
    public abstract int initContentView(Bundle savedInstanceState);

    /**
     * 注入绑定
     */
    private void initViewDataBinding(Bundle savedInstanceState) {
        binding = DataBindingUtil.setContentView(this, initContentView(savedInstanceState));
    }

    public void initViewModel() {

    }
    public void initView() {

    }

    public void initData() {

    }

    public void initViewObservable() {

    }

    /**
     * 显示标题
     */
    public void setWhiteActionBarStyle(String title) {
        /**
         * 标题
         */
        TextView title_text = findViewById(R.id.title_text);
        title_text.setText(title);
        /**
         * 返回
         */
        ImageView ImageView_Return = findViewById(R.id.ImageView_Return);
        ImageView_Return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }



    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}
